package cn.tedu.luban.account.webapi.service.impl;

import cn.tedu.luban.account.service.IAccountService;
import cn.tedu.luban.account.webapi.mapper.AccountMapper;
import cn.tedu.luban.account.webapi.utils.SecurityContext;
import cn.tedu.luban.commons.enums.account.StatusRecord;
import cn.tedu.luban.commons.pojo.account.dto.AccountDTO;
import cn.tedu.luban.commons.pojo.account.dto.PaymentDTO;
import cn.tedu.luban.commons.pojo.account.model.Account;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
@DubboService
public class AccountServiceImpl implements IAccountService {

    @Autowired
    private AccountMapper accountMapper;

    @Override
    public Account getAccountByUserId(Long userId) {
        Account account=accountMapper.getAccountByUserId(userId);
        return account;
    }

    @Override
    public Long create(AccountDTO accountDTO) {
        return null;
    }

    @Override
    public Long mockPayment(PaymentDTO paymentDTO) {
        Account account=new Account();
        //Map map=new HashMap();
        BeanUtils.copyProperties(paymentDTO,account);
//        Long userId= SecurityContext.getUserId();
        account.setGmtCreate(System.currentTimeMillis());
        account.setGmtModified(System.currentTimeMillis());
        account.setCreateUserId(paymentDTO.getUserId());
        account.setModifiedUserId(paymentDTO.getUserId());
        account.setCreateUserName( "mock1");
        account.setModifiedUserName( "mock1");
        account.setStatus(StatusRecord.ENABLE.getStatus());
        return accountMapper.updateAmount(account);
    }
}
